package com.py.custom.common.db.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.py.custom.common.db.plugins.SqlPlugin;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * description： springboot自动配置
 *
 * @author pengyou
 * @version 1.0.0
 * @date 2021/10/23
 */
@Configuration
@MapperScan("com.py.custom.data.mapper")
@EnableTransactionManagement
public class DbAutoConfiguration {

    /**
     * 分页插件。如果不配置，分页插件将不生效
     */
    @Bean
    public MybatisPlusInterceptor paginationInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // 指定数据库方言为 MYSQL
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }

    @Bean
    public SqlPlugin sqlPlugin() {
        return new SqlPlugin();
    }
}
